	_helo = _this select 0;
	_airport = _this select 3;
	_egress = _this select 4;
	_ingress = _this select 5;
	_home = _this select 2;
	_callsign = _this select 1;

	_pilot = driver _helo;
	_gunner = gunner _helo;
	_grp = group _pilot;

	_mkrname = format ["%1station",_helo];
	deletemarkerLocal _mkrname;
	_mkrname2 = format ["%1station2",_helo];
	deletemarkerLocal _mkrname2;

	["RTB",[player,_pilot,_callsign]] execVM (RUM_PATH+"AHel\radiodialogs.sqf");
	sleep 8;

	// player globalchat format["in the rtb script:  %1",_this];
	
	// spawn a loop to monitor the helo if its still alive or has been destroyed
	_helo spawn {
		_helo = _this select 0;
		_vehchk = true;
		while {_vehchk} do {
			If (!alive _helo) then {
				player sidechat format ["%1 has crashed or has been destroyed.", _callsign];
				hintsilent format ["%1 has crashed or has been destroyed.", _callsign];
				_vehchk = false;
				exit;	
			}else{
				sleep .05;
			};
		};
	};
	
	_wpAH=_grp addWaypoint [getpos _ingress, 0];
	_wpAH setWaypointType "MOVE";
	_wpAH setWaypointSpeed "LIMITED";
	_wpAH setWaypointBehaviour "CARELESS";
	_wpAH setWaypointCombatMode "BLUE";
	_wpAH setWaypointCompletionRadius 50;
	_helo flyInheight 32;
	sleep 4.75;
	// deleteWaypoint [_grp, 0];

	_wpAH=_grp addWaypoint [getpos _ingress, 0];
	_wpAH setWaypointType "MOVE";
	_wpAH setWaypointSpeed "NORMAL";
	_wpAH setWaypointBehaviour "CARELESS";
	_wpAH setWaypointCombatMode "BLUE";
	_wpAH setWaypointCompletionRadius 50;
	_grp setcurrentWaypoint _wpAH;
	_helo flyInheight RUM_AHEL_flyHeight;

	sleep 1;
	if (surfaceIsWater (getpos _home)) then {
		// player sidechat format["Heli is on LHD or Ship, %1",_heliRoute];

		_heloRTBWaypoint = true;
		
		while {_heloRTBWaypoint} do {
			sleep .05;
			_distanceToIngress = round(_ingress distance _helo);
			hintsilent format["distance from home plate: %1",_distanceToIngress];
			if (_distanceToIngress <=200) then {
				_lz = "HeliHEmpty" createVehicle (getposASL _home);
				_lz setposASL [getPosASL _home];
				_wpAH=_grp addWaypoint [getposASL _lz, 0];
				_wpAH setWaypointType "GETOUT";
				_wpAH setWaypointSpeed "LIMITED";
				_wpAH setWaypointBehaviour "CARELESS";
				_wpAH setWaypointCombatMode "BLUE";
				_wpAH setWaypointCompletionRadius 0;
				_stg = "RUM_AHel_endflight = '"+(format ["%1",_helo])+"'";
				_wpAH setWaypointStatements ["true", _stg];
				// _lz;
				
				// ends the while loop
				// player sidechat "1st Loop ends";
				_heloRTBWaypoint = false;
			};
		};
		
		// starts new while loop for landing procedures...
		_heloRTBWaypointH = true;
		
		while {_heloRTBWaypointH} do {
		// player sidechat "starting 2nd loop...";
			sleep .05;
			_distanceToDeck = round(getposASL _helo select 2);
			_heightToHomePlate = round((getposASL _helo select 2) - (getposASL _home select 2));
			_distToHomePlate = round( _helo distance _home);
			if (_distToHomePlate <= 70) then {
				if (_heightToHomePlate <= 0.5) then {
				sleep 3.5;
				_helo setFuel 0;
				sleep 5;

				// ends the while loop.
				_heloRTBWaypointH = false;
				}else{
					// hintsilent format ["Height Above Home Plate: %1\nDistance to Home Plate: %2",_heightToHomePlate,_distToHomePlate];
				};
			}else{
				// hintsilent format ["Height Above Home Plate: %1",_heightToHomePlate];
			};
		};
	}else{

		// This section of the if statment is for land based helo's
		// player sidechat format["Heli is not over water, %1",_heliRoute];
		// waits till closer to ingress position before moving to final approach.
		waituntil{((_ingress distance [getPos _helo select 0, getPos _helo select 1, 0]) <= 200)};

		_wpAH=_grp addWaypoint [getpos _home, 0];
		_wpAH setWaypointType "GETOUT";
		_wpAH setWaypointSpeed "NORMAL";
		_wpAH setWaypointBehaviour "CARELESS";
		_wpAH setWaypointCombatMode "BLUE";
		_wpAH setWaypointCompletionRadius 50;
		_helo flyInheight (RUM_AHEL_flyHeight - 45);
		_stg = "RUM_AHel_endflight = '"+(format ["%1",_helo])+"'";
		_wpAH setWaypointStatements ["true", _stg];

	};
	
	// player sidechat format[ "before wait: %1, String: %2",RUM_AHel_endflight, _stg];
	_end = format ["%1",_helo];
	sleep 5;
	waitUntil{(!alive _helo) or (RUM_AHel_endflight == _end)};
	// player sidechat format[ "before wait: %1, %2 ",alive _helo,count(crew _helo)];

	// hint "deleting pilots and stuff";
	sleep 1.5;
	_pilot action ["engineOff", _helo];
	doGetOut [_pilot,_gunner];
	sleep 1;
	doGetOut [_pilot,_gunner];
	sleep 1;
	unassignVehicle _pilot;
	deleteVehicle _pilot;
	unassignVehicle _gunner;
	deleteVehicle _gunner;
	deleteVehicle _lz;

	sleep 5;
	// hint "end flight wait ended";
	if ((alive _helo) and (count(crew _helo) == 0)) then {
		player sidechat format ["%1 has landed safely.", _callsign];
		// hintsilent format ["%1 has landed safely.", _callsign];
		sleep 2;
		player sidechat format ["%1 is being rearmed/refueled at this time and will be avaiable in %2 mics.", _callsign, (RUM_AHEL_ReSupTime/60)];
		// hintsilent format ["%1 is being rearmed/refueled at this time and will be avaiable in %2 mics.", _callsign, (RUM_AHEL_ReSupTime/60)];
	// checks to see if the helo is either on a LHD deck over water or on land
		if (surfaceIsWater (getpos _home)) then {
			// player sidechat format["Heli is on LHD or Ship, %1",_helo];
			_helo setPosASL _heliPosASL;
		}else{
			// player sidechat format["Heli is not over water, %1",_helo];
			_helo setpos getpos _home;
		};
		_helo setdir getdir _home;
		_helo setDamage 0;
		_helo setFuel 1;
		_mags = getArray (configFile>>"cfgVehicles">>typeOf _helo>>"Turrets">>"MainTurret">>"magazines");
		{_helo removeMagazine _x} forEach magazines _helo;
		{_helo addMagazine _x} forEach _mags;
	};

	// this will add the vehicle back to the RUM PDA when resupply has finished. (still has an issue with var passed back)
	// player sidechat format["%1",_arry];

	sleep RUM_AHEL_ReSupTime;
	
	RUM_AHelAircraft = RUM_AHelAircraft + [_arry];
	_helo setVariable ["RUM_inFlight", false, true];

if(true)exitwith{};
